const connection = require("../app/database");

class LabelService {
  async create(name) {
    const statement = "INSERT INTO label(name) VALUES (?)";

    const [result] = await connection.execute(statement, [name]);
    return result;
  }

  async list(offset = 0, size = 5) {
    const statement = "SELECT * FROM label LIMiT ? OFFSET ?;";
    const [result] = await connection.execute(statement, [
      String(size),
      String(offset),
    ]);
    return result;
  }

  async queryLabelByName(name) {
    const statement = "SELECT * FROM label WHERE name = ?";
    const [result] = await connection.execute(statement, [name]);
    return result;
  }
}

module.exports = new LabelService();
